package cn.ren.cloud.result;

import lombok.Data;

/**
 * @author 23508
 * @Builder 建造者模式
 * <p>
 * 返回JSON结果
 */
@Data
//@Builder
public class JsonResult {

    private boolean success = true;

    private String message = "成功";

    /**
     * 错误码，用来描述错误类型 ，1000 表示么有错误
     **/
    private String code = "1000";

    /**
     * 返回的数据
     **/
    private Object data;


    public JsonResult() {

    }

    /**
     * 创建当前实例
     **/
    public static JsonResult success() {
        return new JsonResult();
    }

    /**
     * 创建当前实例
     **/
    public static JsonResult success(Object obj) {
        JsonResult instance = new JsonResult();
        instance.setData(obj);
        return instance;
    }

    public static JsonResult success(Object obj, String code) {
        JsonResult instance = new JsonResult();
        instance.setCode(code);
        instance.setData(obj);
        return instance;
    }

    /**
     * 创建当前实例
     **/

    public static JsonResult error(String message, String code) {
        JsonResult instance = new JsonResult();
        instance.setMessage(message);
        instance.setSuccess(false);
        instance.setCode(code);
        return instance;
    }

    public static JsonResult error() {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setSuccess(false);
        return jsonResult;
    }

    /**
     * 创建当前实例
     **/
    public static JsonResult error(String message) {
        return error(message, null);
    }

}
